package com.cloud.form.api.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.form.api.bean.FormRepositoryCriteria;
import com.cloud.form.api.entity.FormDef;
import com.cloud.form.api.entity.RepoFormAssemblyInst;
import com.cloud.form.api.service.FormRepositoryService;
import com.cloud.form.common.result.Quokka;

@RestController
@RequestMapping("/form/api/repository")
public class FormRepositoryController {

	@Autowired
	private FormRepositoryService formRepositoryService;

	@RequestMapping("listpage")
	public Quokka listFormPage(@RequestBody FormRepositoryCriteria criteria) {
		return new Quokka(true, formRepositoryService.listFormPage(criteria));
	}

	@RequestMapping("push")
	public Quokka pushForm(long formId) {
		formRepositoryService.pushForm(formId);
		return new Quokka(true);
	}

	@RequestMapping("assemblies")
	public Quokka listAssemblies(Long id) {
		List<RepoFormAssemblyInst> insts = formRepositoryService.listAssemblies(id);
		return new Quokka(true, insts);
	}

	@RequestMapping("pull")
	public Quokka pullForm(@RequestBody FormDef formDef, Long repoFormId) {
		formRepositoryService.pullForm(formDef, repoFormId);
		return new Quokka(true);
	}
	
	@RequestMapping("delete")
	public Quokka delete(long id) {
		formRepositoryService.delete(id);
		return new Quokka(true);
	}
	
	@GetMapping("loadprintform")
	public Quokka loadPrintForm(Long id){
		return new Quokka(true, formRepositoryService.loadPrintForm(id));
	}
}
